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

Sort a two dimensional array.
Hi. I've set up a two dimensional array that reads as follows:

Code: $modifiedData = array(

Curl timeout breaks script
So im having difficulties with skipping timeout error in curl
my script calls different functions

apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?

mysql_real_escape_string making variable equal nothing
i post a form and i post the variable:
Code: $var = $_POST[variable];then i echo $var its what i

Parse XML
Good day,

I use oempro software and try to parse XMLReturn but it's not working for me, simpl

quick question
Hi ..

i have a question
how do i set a var so it displays via an echo
Code: $logo = '&a

Help with simple query
Hi,

I'm trying to do a Query with a Union where I want to print the number of rows $tc conta

Word Trimming
Hi Guys & Gals!!

Hope you are all ok....

I need some help with the following

please fix the error
What is the error in the below code ???
Line number On/Off | Expand/Contract <?php

A WBS element with the name XXX already exists in version FREI_VERSION
Hi.
When I am trying to insert WBS element in a project, error occurs:

"A WBS eleme

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