/    Sign up×
Community /Pin to ProfileBookmark

Connecting to mysql problem

Alright.. I set up my database, the cmdlines work and all.

But when I use the PHP functions to connect, nothing happens…

I’m not sure if it worked or not..

[code=php]@mysql_connect($host, $user, $pass)
or die(“Unable to connect to server”);[/code]

Like when I do that nothing happens. Even when I input invalid data. How do I check if I successfully logged onto the database through PHP?

EDIT:
Well, it seems like I can’t even get MySQL to work with PHP 5. I followed all the directions online and people having the same problem. I even typed
“php -m” in console and see that mysql extension is loaded… but for some reason, there still exist a fatal error of undefined function mysql_connect().

FIXED:
Oh my goodness… I had the php.ini file path directory all wrong in the httpd.conf in apache… duh.

-Pizzaman

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@grailquester5Apr 29.2005 — Well, the '@' sign suppresses errors, so removing it would be a start. At least then you should see the error when the database doesn't connect...
Copy linkTweet thisAlerts:
@pizzamanauthorApr 29.2005 — Alright, I removed the '@' and the following comes up.

Fatal error: Call to undefined function mysql_connect() in C:Documents and SettingsRobMy DocumentsMy Websitesqltest.php on line 12

Uh was i suppose to set some path somewhere?

-Pizzaman
Copy linkTweet thisAlerts:
@grailquester5Apr 29.2005 — No - are you storing the file locally on your computer? Do you have PHP installed on your computer?
Copy linkTweet thisAlerts:
@grailquester5Apr 29.2005 — Oh, duh - you need to assign a resource link to the function call, like so:
[code=php]
$dbc = mysql_connect(HOST, USER, PASSWORD);
[/code]

See if that doesn't help.
Copy linkTweet thisAlerts:
@pizzamanauthorApr 29.2005 — Nope still the same.

I think assigning a link is only usefull if you have numerous databases. I got PHP on my computer, and MySQL. Hmm... I might have missed something during the configuration in the PHP.ini file? Maybe there is something i need to uncomment there? DOn't know.

-Pizzaman
Copy linkTweet thisAlerts:
@pizzamanauthorApr 29.2005 — Oooh i think i know why. PHP 5 no longer bundles the MySQL libraries.
Copy linkTweet thisAlerts:
@imnoguruApr 29.2005 — <?php

$connection = @mysql_connect( "host", "login", "pass" )

or die( "Could not connect." );

if ( $connection ) {

$msg = "Success!!";

}

?>

Of course if you'd like to see what kind of errors, remove the @ like he said before.

-imnoguru
Copy linkTweet thisAlerts:
@grailquester5Apr 29.2005 — Ah, you're using PHP5! The syntax and functions have changed!!

Try:
[code=php]
$dbc = new mysqli('host', 'username', 'password', 'database');

// or, using PHP4 syntax it would be:
$dbc = mysqli_connect('host', 'username', 'password', 'database');

// Your query structure is now:
$result = $dbc->query($query);

// or, in old PHP4 syntax:
$result = mysqli_query($dbc, $query);
[/code]

The difference is that the new PHP5 method accesses the database connection in an object-oriented approach, whereas the PHP4 version is a procedural approach...
Copy linkTweet thisAlerts:
@chestertbMay 01.2005 — Great! :-(

Now I have to rewrite all of my scripts to detect 5, of <5, and then execute mysql commands accordingly, just because someone at PHP decided they wanted to be "politically correct" and go object oriented.

Was it broken the old way? No. And if it aint broke, don't fix it!

Not happy.
Copy linkTweet thisAlerts:
@grailquester5May 01.2005 — Well, I think it would only matter if you were managing files across multiple servers. Since the server parses the PHP, it only matters what the server is running, and if its your server, you could keep it running PHP4 for as long as you'd like...
Copy linkTweet thisAlerts:
@chestertbMay 01.2005 — Or it would matter if I was writing a script set that I was going to make available under a GPL. Ah well. Shelve that plan and keep it for myself.

Still not happy, but I accept the point grailquester5.

Cheers

CTB
Copy linkTweet thisAlerts:
@grailquester5May 01.2005 — Aw dang! Hadn't thought of that. I just finished developing an intended GPL myself - of course coded for PHP4... Well... that's certainly a very interesting dilemma...
×

Success!

Help @pizzaman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...