List:MySQL and PHP« Previous MessageNext Message »
From:Rick Olson Date:July 19 2007 5:30pm
Subject:Re: php not working with MySQL database
View as plain text  
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
Thread
php not working with MySQL databaseJimmy Wu19 Jul
  • Re: php not working with MySQL databaseRick Olson19 Jul
    • Re: php not working with MySQL databaseJimmy Wu19 Jul
      • Re: php not working with MySQL databaseGary Josack19 Jul
        • Re: php not working with MySQL databaseSylvain Tousignant20 Jul
          • Re: php not working with MySQL databaseGary Josack20 Jul
          • Re: php not working with MySQL databaseJimmy Wu20 Jul