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 (){
Did you know?Explore Trending and Topic pages for more stories like this.
$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

Disable Scrollbar in TableControl
Hello everbody,

please can anybody help me - outherwise i'm going to become desperate :P<

MySQL-PHP Query Results Help
Hello all. I'm hoping to be able to get some help in solving a problem with query/rowcount output. I

Redirecting Admin
In my members table, I have a field called "perm" and it's set to zero for all members. Ho

Displaying pictures
i have worked my way through storing images in directory and storing the location in mySQL db.Now i

Printing issues with xMII 11.5
For some reason, we have one report (and only one) that is giving us fits when trying to print. The

records between 2 dates
Hello all,

I have a date tracked table which contains effective_start_date and effective

PHP Surveys
I really would like some advice.

If you have a client come to you asking for a survey to be d

MySQL noob question
hi guys

I have a simple mysql table set up, along the lines of

Col 1 - Col 2 - Date_l

small inaccuracies
I have this code to convert fractional base 10 into base 2:

while($num > 0)

Insert Failing.
Hey,
I am making a Sign up page for a website, but the insert query into the Database does not se

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