php - When I type in connect() to my database, my localhost server comes up blank -
is connect() function depecrated or something? when seek connect mysql database using function, page stops working? i'm doing jeffrey ways 30daysjquery course of study lesson 25
here's code in index.php file
<?php require 'functions.php' if ( isset($_post['q'])) { connect(); } include 'views/index.tmpl.php' ?>
this code in functions.php file
<?php function connect(){ global $pdo; // set global other functions can access $pdo = new pdo("mysql:host=localhost;dbname=sakila", "root", "root"); } function get_actors (){ } ?>
might not have access content that's in functions.php? if how create access?
your function should maybe homecoming connection:
function connect(){ $pdo = new pdo("mysql:host=localhost;dbname=sakila", "root", "root"); homecoming $pdo; }
then, function get_actors()
be
$db_connection = connect(); get_actors( $db_connection ); function get_actors( $pdo ) { // // utilize database connection $pdo actors // }
you have add together parameter function get_actors
. no need modify code function.
php mysql
No comments:
Post a Comment