Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 18th, 2007, 05:25 AM
soft_devjava@yahoo.com
Guest
 
Posts: n/a
Default got trouble connection to mysql5 using php5...need help

my environment:
===========================
-php ver 5.2.0
-mysql 5
-windows xp
-apache 2
-all of these are on the same machine

my code:
==========================
<html>
<body>

<?php
echo "browsing users";

$conn=new mysqli("localhost","dba","masterkey","tms");
if(mysqli_connect_errno()){
echo "Connection Error";
exit;
}

$query="select username from reg_user";
$result=$conn->query($query);
$num_results=$result->num_rows;

echo "<p>num of records found: ".$num_results."</p>";


for($i=0; $i<$num_results; $i++){
$row=$result->fetch_assoc();
echo "<br/Username: ";
echo stripslashes($row['username']);
}
$result->free();
$conn->close();
?>

</body>
</html>


problem
==========================
-if i run the code the only thing that shows is "browsing users".
-this line >echo "<p>num of records found: ".$num_results."</p>"; <<
is not also showing up
-is there something wrong with my code...logic..or syntax?
-or i wasnt able to obtain communication with mysql that's why nothing
appears. and if so, what have gone wrong why i cannot to mysql?

  #2  
Old January 18th, 2007, 01:55 PM
Erwin Moller
Guest
 
Posts: n/a
Default Re: got trouble connection to mysql5 using php5...need help

soft_devjava@yahoo.com wrote:
Quote:
my environment:
===========================
-php ver 5.2.0
-mysql 5
-windows xp
-apache 2
-all of these are on the same machine
>
my code:
==========================
<html>
<body>
>
<?php
echo "browsing users";
>
$conn=new mysqli("localhost","dba","masterkey","tms");
if(mysqli_connect_errno()){
echo "Connection Error";
exit;
}
>
$query="select username from reg_user";
$result=$conn->query($query);
$num_results=$result->num_rows;
>
echo "<p>num of records found: ".$num_results."</p>";
>
>
for($i=0; $i<$num_results; $i++){
$row=$result->fetch_assoc();
echo "<br/Username: ";
echo stripslashes($row['username']);
}
$result->free();
$conn->close();
?>
>
</body>
</html>
>
>
problem
==========================
-if i run the code the only thing that shows is "browsing users".
-this line >echo "<p>num of records found: ".$num_results."</p>"; <<
is not also showing up
-is there something wrong with my code...logic..or syntax?
-or i wasnt able to obtain communication with mysql that's why nothing
appears. and if so, what have gone wrong why i cannot to mysql?
Which Database abstraction layer are you using?

$conn=new mysqli("localhost","dba","masterkey","tms");
is only valid if some classdefinition of mysqli exists.

And did you try to connect to the database without the abstractionlayer?
Also check if you updated your php.ini so it uses mysqli.dll instead of
mysql.dll.
In such cases I always check first if things connect succesfull by using php
native commands first before using the abstractionlayer.

Regards,
Erwin Moller
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles