Thank you Sylvain et al for your help - it works now :-)
@Gary: you were right - I'm a beginner at both php and MySQL and I should
have checked the mysqli reference before bothering the mailing list. Sorry
- Jimmy
On 7/20/07, Sylvain Tousignant <sylvaint@stripped> 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:
> >>
> >> <?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
> >>>
> >
>