From: Gary Josack Date: July 20 2007 5:29am Subject: Re: php not working with MySQL database List-Archive: http://lists.mysql.com/php/17 Message-Id: <1184909381.809B00C@dk12.dngr.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format="flowed" Content-Transfer-Encoding: 7bit whoops. I forgot I was on the php/mysql list since I was replying from phone and it doesn't display errors. I wasn't necessarily being mean about it, more suggesting that the php list would probably me faster and more helpful. On Fri, 20 Jul 2007 12:39 am, Sylvain Tousignant wrote: > Hello Jimmy, > > What you are doing wrong is quite simple. You forgot to add the > connection parameter to the mysqli_query function. And you inverted > the order of the parameters for the musqli_select_db function. > > Change this line from > > $result = mysqli_query($con, "SELECT * FROM users;"); > > to > > $result = mysqli_query("SELECT * FROM users;"); > > also, Change this line from > > mysqli_select_db("criki", $con); > > to > > mysqli_select_db( $con, "criki"); > > You really should read up on the function in the PHP Manual, otherwise > you'll never use the entire potential of the mysqli extension. > > Here is the link : > http://www.php.net/manual/en/ref.mysqli.php > > BTW, Gary, this is the PHP/MySQL list. While I agree that the list > should be specific to the MySQL problems, I think that our friend Jimmy > had a valid reason for using this list since he did have problems > connecting to MySQL from PHP. > > Good luck Jimmy > > Sylvain. > > > Gary Josack wrote: >> this is a mysql mailing list, not php so you might want to try and >> that one though I THINK the problem is you're trying to echo as if it >> was an associative array. >> >> try to echo as row[0] and row[1] >> >> though this might be wrong its worth a shot ;) >> >> On Thu, 19 Jul 2007 2:35 pm, Jimmy Wu wrote: >>> Thanks to all for your help, >>> >>> Switching to mysqli fixed the problem >>> Now the script executes to the end (the "echo 'done';" statement), but >>> there's still some glitches left over. >>> >>> The script is intended to display all rows in table users in database >>> criki. There are two rows in that table now, but the script runs right >>> through, displaying "hi*" from 1 to 4 with no rows displayed at all. >>> What >>> am I doing wrong now? >>> >>> Here is an updated version of the script: >>> >>> >> echo "begin"."
"; >>> $con = mysqli_connect("localhost", "root", "jxywr00t"); >>> echo "hi
"; >>> >>> if (!$con) >>> { >>> echo "die"; >>> die('Could not connect: ' . mysql_error()); >>> } >>> echo "hi2
"; >>> >>> >>> mysqli_select_db("criki", $con); >>> echo "hi3
"; >>> $result = mysqli_query("SELECT * FROM users;"); >>> echo "hi3 A
"; >>> while($row = mysqli_fetch_array($result)) >>> { >>> echo $row['id'] . ": " . $row['username']; >>> echo "
"; >>> } >>> echo "hi4
"; >>> >>> >>> mysqli_close($con); >>> echo "done"; >>> ?> >>> >>> Thanks, >>> >>> Jimmy >>> >>> >>> >>> On 7/19/07, Rick Olson wrote: >>>> >>>> >>>> Jimmy Wu wrote: >>>>> Hi >>>>> >>>>> I have php 5.2 installed on a Windows XP Pro, along with Apache >>>>> 2.2 and >>>>> MySQL 5.0 >>>>> The server (host) I'm using is localhost, and my php scripts run >>>>> normally, >>>>> except when trying to connect to MySQL >>>>> >>>>> I have the following php script >>>>> >>>>> >>>> echo "begin"."
"; >>>>> $con = mysqli_connect("localhost", "root", "***********"); >>>>> echo "hi
"; >>>>> >>>>> if (!$con) >>>>> { >>>>> echo "die"; >>>>> die('Could not connect: ' . mysql_error()); >>>>> } >>>>> echo "hi2"; >>>>> >>>>> >>>>> mysql_select_db("cake", $con); >>>>> echo "hi3"; >>>>> $result = mysql_query("SELECT * FROM users;"); >>>>> >>>>> while($row = mysql_fetch_array($result)) >>>>> { >>>>> echo $row['id'] . ": " . $row['username']; >>>>> echo "
"; >>>>> } >>>>> echo "hi4"; >>>>> >>>>> >>>>> mysql_close($con); >>>>> echo "done"; >>>>> ?> >>>>> >>>>> I have set up the MySQL database called cake, along with the table >>>> called >>>>> users, with one entry in it. >>>>> >>>>> However, the script inexplicably stops after echoing hi2. >>>>> >>>>> That means it must be connecting to the mysql server alright, and it >>>>> must be >>>>> stopping at the mysql_select_db, since it never gets to hi3. >>>>> >>>>> I can't figure out what's wrong, and I would appreciate any >>>>> help/suggestions. >>>>> >>>>> Thanks, >>>>> >>>>> Jimmy >>>>> >>>> >>>> Hello, >>>> >>>> You are using mysql_* functions with a mysqli object. You need to use >>>> the mysqli_* functions (http://www.php.net/mysqli). >>>> >>>> -- >>>> Rick >>>> http://www.sensual.jp >>>> >> > > -- > MySQL PHP Mailing List > For list archives: http://lists.mysql.com/php > To unsubscribe: http://lists.mysql.com/php?unsub=lists@stripped