/    Sign up×
Community /Pin to ProfileBookmark

Can anyone explain this discrepancy

I have looked at many php scripts for accessing mysql databases and every one is structured along the lines of the following.

Example
————

$db = mysql_connect($server, $db_user,$db_pass);
mysql_select_db($database,$db);
$insert = mysql_query(“INSERT INTO useronline VALUES (‘$timestamp’,’$REMOTE_ADDR’,’$PHP_SELF’)”,$db);

If I try to use these on my server, I get errors.

I have to use something like this
————–

$dbh = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name);
$dbc = mysql_query(“select * from grandscores”);

You can see that I have to leave out the mysql handle returned by mysql_connect, in both mysql_select_db and mysql_query otherwise it will not work.

I have checked the mysql manual and find the following.
————-

int mysql_select_db(MYSQL *mysql, const char *db)
int mysql_query(MYSQL *mysql, const char *query)

In mysql_select_db and mysql_query, the handle is the first parameter which is different to both the above examples.

Can anyone explain what is going on?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @design_dragon 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.17,
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,
)...