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

sql problems
I am having a small problem with my sql statement. it is inserting into 4 of the fields.

fie

Option box to change variable
Hello, i need help by making a script!

I need to write a file with option box, so a dropdown

How to generate a text file using php...?
Hi,
Can anyone give me code to generate a text file using php


Thanks in advance

can i optmize image to 50% quality before uploading 2 server
Hi there

i have jus written a php program to upload and display images but when i try to uplo

Pass sql into pl/sql and create RMAN duplicate script.
Hi,

I'm new to pl/sql and I'm trying to write a script that will generate some RMAN comma

PHP Function Page Advice
Hi All, I am quite new to PHP and Javascript but have written an Online Shop (Mainly for Fun and edu

InternetOpenUrl() Invalid cert
Hi all,

Does anyone know how to prevent calls to InternetOpenUrl() from failing with erro

need Array help
This is what I have to do.
$teamname[1] = "Red Sox"
$teamname[2] = "Gian

Which PHP-Editor do you think is the best?
Hi everyone,
Myself Brian Anderson. For the last 2 years i have been working a

php require help needed
Ok i tried to use the search funtion but the word require is everywhere.

i'm really new to cr

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