Jump to content

[SOLVED] Very frustrating mysql/PHP problem


msininism

Recommended Posts

Hello,

 

I have a laptop with apache, php, and mysql 5.0.27 installed.  all three of them work fine and i have no problems working any one of them. my problem is that i can't integrate php and mysql on my laptop.  i used dreamweaver to create a simple mysql connect script and the page comes up blank.

 

here is my script, except my variables were changed to fit my database.

_______________

<?php

$link = mysql_connect("localhost", "mysql", "pw") or die("Connection failed: " . mysql_error());

if ($link) {

echo "Connection successful"; }

?>

 

i've entered in everything correct as well as making typos purposely to see if that had anything to do with it.  no matter what i do, it will still come up blank.

 

ive added the mysql extensions to php and edited php.ini according to a wiki on forge.mysql.com .  i created a phpinfo.php file and ran it and these are the results under mysqli

http://www.rosspractice.com/mysqli.jpg

 

ive been trying to find an answer to my problem for the last few days, and nobodys been able to help me.  can someone please help me?

 

- ross

 

 

Link to comment
Share on other sites

the reason the page is blank is that the connection is throwing an error, it is not showing you it because you are storing the error in $link

change you code to

 

<?php
$link = mysql_connect("localhost", "mysql", "pw") or die("Connection failed: " . mysql_error());
if ($link) 
{
echo "Connection successful"; 
}
else 
{
echo $link;
}
?>

Link to comment
Share on other sites

it wasn't the username/password combo, i wasn't sure what it was. 

 

i looked around and found someone with the same problem and they used these lines of code

 

<?php

$conn = mysqli_connect('localhost', 'userone', 'password', 'dbname') or die  ('Error connecting to mysql');

 

echo "connection established";

?>

 

i fixed the variables and was able to get the "connection established" message.  the only problem i have now is that when i run a homemade php application, i get a "connection established" message whenever mysql table data is supposed to appear.  i know that the php application works because i tested out months ago on a verio webserver where everything was already installed and configured for me.  the only thing im changing between this and that is the mysql connect script, and that script works on its own.

 

i entered in data manually through my mysql command line client and when i tried to view it through my php file, nothing would show up.  its like, theres a connection that is definitely established, yet the php file and the mysql database will not communicate.

Link to comment
Share on other sites

I know you solved this, by using the mysqli_connect function but the problem was you was using mysql_connect to connect to the MySQL server but you have the mysqli extension enabled.

 

You cannot use the mysql function library (mysql_connect, mysql_query etc) with that extension. You must use the mysql improved (mysqli - mysqli_connect) function set.

 

php_mysql.dll and php_mysqli.dll have different function sets.

Link to comment
Share on other sites

Thank you all very much for all the help.  I went to the php.ini file and changed the following

 

Directory in which the loadable extensions (modules) reside.

extension_dir = C:\Program Files\PHP\ext

// MySQLi extension

extension=php_mysqli.dll

 

to

 

Directory in which the loadable extensions (modules) reside.

extension_dir = C:\Program Files\PHP\ext

// MySQL extension

extension=php_mysql.dll

 

something so simple but i didn't think about it until wildteen mentioned that mysqli and mysql had different function sets.

 

thanks again to everyone who tried to help me out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.