problem when runing a funciton


Posted on 16th Feb 2014 07:03 pm by admin

I am trying to connect to database using a funciton in a functions.php

<?php
function connect_db_Blog (){
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("blog",$con);
}
?>
which I then include with
include ("scripts/php_functions.php");

but when I run a code with

connect_db_Blog();

var_dump($db);
if (!$db) {

echo "sorry, cannot connect to database";

} else {
here comes some code..

I get: sorry , cennot connect to database message.

when I listen for $db with
var_dump($db);
I get int(0);
instead of int(1) which is needed to proceed with the code.

If I just try to connect to database without the include I dont get the error message i.e. .

No comments posted yet

Your Answer:

Login to answer
311 Like 17 Dislike
Previous forums Next forums
Other forums

Please help - should be a simple fix.. driving me nuts
Everything seemed to be working fine. I have a table, it alphabetically lists a bunch of cities and

Sending a hyperlink through mail
HI all,
I am sending a mail to outlook mailbox of a user using FM SO_NEW_DOCUMENT_ATT_S

foreach iterator
Hi Guys
Does the foreach loop have an inbuilt iterator ?

Get last modified date of web page
Hai All,

In php how can i get last modified date of a give web page . I have tried to g

getting weird error..
okay, I'm getting an error on this particular function, something about the syntax in the mysql LIMI

my sql select id and then update problem.
I need to select some auto incremented ids out of a database and then use those id in a where statem

printing links
Hi every1

i am connecting to a table in sql and the looping through with a while ($ var = my

FROM_UNIXTIME($phpdate);
Hello,

I tried to use this :

$date = FROM_UNIXTIME($phpdate);

ANd I was t

Turning Data into URLs?
This may seem very basic to you, but I'm having a hard time figuring out how to do this since I don'

cURL Sending File as Post
This is a bit complicated, I'm just hoping someone else has run into this and knows how to do it a d

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash