/    Sign up×
Community /Pin to ProfileBookmark

Function to connect to mysql

Hi:

I use a web host that runs:
PHP 4.3.10 with
MySQL 3.23.58 on
Apache 1.3.33

When I run a function to get values from the database through connecting then SELECT, it is successful. However, when I adjust the function to simply connect, it would appear not to be successful. And I’m stumped as to why. Script and output below …

~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?php

function db_connect()
{

$db = mysql_pconnect(“db:4000:/usr/bin/mysql”,”name”,”PW”);

if (!$db)
{
echo ‘Error: Could not connect to database. Please try again later.’;
return false;
exit;
}

// else ..
if (!mysql_select_db(“scizors”,$db));
return false;
if (mysql_select_db(“scizors”,$db));
return true;
}

// Function is used in script

$connected = db_connect();
echo “db_connect = “, $connected;
?>

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

<html>
<head>
<title>Untitled</title>
</head>
<body>
<BR><BR>
<?php
if ($connected === true)
echo “Connected”;
if ($connected === false)
echo “Not connected”;
?>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The output:

db_connect =
Not connected
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So it would not seem to work. It’s got to be something simple. Any ideas?
Thanks guys.
tork

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@rch10007Aug 23.2005 — Try this:

[code=php]
<?
$link = mysql_connect ( "db:4000:/usr/bin/mysql","scizors","784crude" );

$dbs_list = mysql_list_dbs ( $link );

while ( $row = mysql_fetch_object ( $dbs_list ) )

{
foreach ( $row as $key => $value )
{
echo ( $value . "n" );
}
}
?>
[/code]


Sorry had to edit - gave you the wrong code. It should be right now.
Copy linkTweet thisAlerts:
@torkauthorAug 23.2005 — Thanks! I'll work on this ..

tork
×

Success!

Help @tork 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...