A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearPHP ignoring mysql_connect requests - page 1
User InfoPosts
PHP ignoring mysql_connect requests#1
I'm new to PHP and have installed on Linux to boot (also a newbie).
Anyway, PHP is working...

<?
$myVar = "test";
echo($myVar);
?>


... works just fine.

But...

<?

$dbhost = "localhost";
$dbuser = "myuser";
$dbpass = "mypass";
$dbname = "mydb";

echo($dbhost . "-" . $dbuser . "-" . $dbpass . "-" . $dbname);

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to MySQL");
print $conn;

mysql_close($conn);

phpInfo();
?>


... does nothing. Nor errors, nothing. Its as if the code isn't even there.

Any help?

posted date: 2008-12-24 10:54:00


Re: PHP ignoring mysql_connect requests#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-24 10:54:01


Re: PHP ignoring mysql_connect requests#3
If it does nothing, doesn't that mean that it connected fine? What output do you expect out of that statement?You could tryerror_reporting(E_ALL);$conn = mysql_connect("localhost", "myusername", "mypassword");if(!$conn) { echo 'Unable to connect';} else { echo 'Connected to database';}var_dump($conn);edit: Addressing the comment saying that you have a mysql query setup, if you are not seeing "success" it means something is wrong with your query. Add to the above$sth = mysql_query("SELECT * FROM tablename");if(!$sth) { echo 'unable to query: ' . mysql_error();} else { echo 'success';}

posted date: 2008-12-24 11:01:00


Re: PHP ignoring mysql_connect requests#4
This code is supposed to create a db connection, nothing else. What do you expect to see?Try this<?php$conn = mysql_connect("localhost", "myusername", "mypassword") or die("Unable to connect");print("code sample");print $conn;?>It should print you something like "resource #1"...And then you may use that connection to communicate with db server

posted date: 2008-12-24 11:02:00


Re: PHP ignoring mysql_connect requests#5
Try to do the following:First make sure display_errors is turned on in your php configuration file. Also set the level of error_reporting to show all errors, including strict (error_reporting = E_ALL|E_STRICT). After you make changes, restart your webserver.Run phpinfo(), and check that the mysql extension is installed and working. If it isn't make sure that you uncommented it in the php configuration file (again, remember to restart apache after each change to the configuration file).At this point MySQL should be loaded and working, and you should be able to tell from the error (if it persists) what's the problem.Try also dumping the contents of the connection result ($conn) to see what it contains.In general, I'd recommend using long php tags (<?php and not <?) since it is more portable (short tags are off by default in PHP 5 installations).

posted date: 2008-12-24 11:04:00


Re: PHP ignoring mysql_connect requests#6
Try adding this to the top of your code:error_reporting(E_ALL);

posted date: 2008-12-24 11:11:00


Re: PHP ignoring mysql_connect requests#7
Ok, thats a start. Enabled errors, and nothing. But phpinfo() told me the following. Nowhere in the output is mysql found except in the Configure Command section, I see --without-mysql. I'm assumint that's self explanatory. However, how do I turn mysql on?

posted date: 2008-12-24 11:12:00


Re: PHP ignoring mysql_connect requests#8
did you uncomment the mysql extension in the PHP configuration file? Also did you check that the MySQL server is running?

posted date: 2008-12-24 11:21:00


Re: PHP ignoring mysql_connect requests#9
I don't see anything in the php.ini file with mysql relations that is commented out. And yes, mysqladmin and coldfusion both return results from mysql. Does apache need any sort of mysql module?

posted date: 2008-12-24 11:27:00


Re: PHP ignoring mysql_connect requests#10
I've added my answer with another suggestion for debugging (4,5) also, as others have suggested the problem might be with the sorrounding code. Please post some more of your code.

posted date: 2008-12-24 11:33:00


Re: PHP ignoring mysql_connect requests#11
I've edited my original question with ALL of the code I have on this page. If I comment out the $conn line, I get results, errors, or whatever. If I leave the $conn line in, it STOPS dead, doesn't display the phpInfo() or anything.

posted date: 2008-12-24 11:42:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.