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:
>
> <?php
> echo "begin"."<BR/>";
> $con = mysqli_connect("localhost", "root", "jxywr00t");
> echo "hi <BR/>";
>
> if (!$con)
> {
> echo "die";
> die('Could not connect: ' . mysql_error());
> }
> echo "hi2 <BR>";
>
>
> mysqli_select_db("criki", $con);
> echo "hi3<BR>";
> $result = mysqli_query("SELECT * FROM users;");
> echo "hi3 A <BR>";
> while($row = mysqli_fetch_array($result))
> {
> echo $row['id'] . ": " . $row['username'];
> echo "<br />";
> }
> echo "hi4 <BR>";
>
>
> mysqli_close($con);
> echo "done";
> ?>
>
> Thanks,
>
> Jimmy
>
>
>
> On 7/19/07, Rick Olson <rick@stripped> 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
>>>
>>> <?php
>>> echo "begin"."<BR/>";
>>> $con = mysqli_connect("localhost", "root", "***********");
>>> echo "hi <BR/>";
>>>
>>> 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 "<br />";
>>> }
>>> 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
>>