PHP Tutorials: Register & Login (Part 4): Database Connection

preview_player
Показать описание

Official site

Twitter
Рекомендации по теме
Комментарии
Автор

Dude... you really are the best. Thank you for showing us how to actually order up our files. It's great! Keep up

RazvanMerdescu
Автор

Very organised. This gives the website a professional look!

Thanks Alex!

VijayNandwani
Автор

Alex I have to ask why you are using old mysql_ functions when they are going to be removed in future releases? I'm using PDO myself and its better for a ton of reasons.

DanielJohnHowTo
Автор

This worked for me if you are having problems with the connect.php file

<?php
$connect_error = 'Error message';
$con = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con, 'test') or die($connect_error);
?>

zron
Автор

nemanja1a2a Thank you for fixing that error! Wouldn't have found it without you (y)

LowHeartRate
Автор

This really helps my project in my school

MrPawnyeta
Автор

wouldnt it be includeing to the header? so its at the top of every page without you puting it there?

jonathansnyder
Автор

For those who are having trouble with mysql connect, try this:

<?php

$DBhost = "localhost";
$DBuser = "root";
$DBpass = "";
$DBname = "dbname";

$DBcon = new MySQLi($DBhost, $DBuser, $DBpass, $DBname);

if ($DBcon->connect_errno) {
die("ERROR : -> ".$DBcon->connect_error);
}

diontaeshuron
Автор

Possibly use PDO instead of mysql_*? :)
I've heard that mysql_* functions are being deprecated and plus PDO is much more secure.
Example:
$dbh = new PDO("mysql:host=localhost;dbname=database_name", "mysql_user", "mysql_password);
And querys are like this: $q = $dbh->query("SELECT * FROM table");

duhminick
Автор

Hi, what would you suggest as an alternative to mySQL connect?

aqliam
Автор

do you think it's best to move through the entire course with mysql_connect and then, go back and change to PDO or do it now before moving on?

burpwind
Автор

I resolved it at last. The problem lied within the index.php file, I needed to put include 'core/init.php'; before include 'core/overall/header.php';.

philipekman
Автор

hello alex,

in head.php there is screen.css but why the css cann't run while I preview the index.php in mybrowser

thanks bfore...

miggysatria
Автор

uh-oh mysql is depreciated for anyone getting an error.

replace anything called "mysql" with "mysqli"

this is why code is sometime frustrating. no freaking standards!

hollyplyler
Автор

hey am usin xampp and hav all da php files in da folder "htdocs" and now where should i hav my html files?

guhandelta
Автор

Deprecated mysql_, and include continues where require shows errors: In connect.php, replace mysql_connect and the next line with: mysqli_connect('localhost', 'root', '', 'lr') or die($connect_error);
then in index.php change include 'core/init.php'; into require ''core/init.php';.
When you change the params of mysqli_connect to check errors, it will show the error msg.

elsbrussee
Автор

me too.. did you find how to fix it ?

adel
Автор

Your solution is working.. thanks bro.. but hv you find the solution by keeping the code into init and even then to not get error..

GauravSingh-vvmd
Автор

why doesn't require use the full directory name, i.e. "core/database/connect.php" ?

dayuloli
Автор

Maybe, check that you have correctly written the $connect_error = 'Sorry we\'re experiencing downtime.'; variable I missed the semicolon and got a white screen.

burpwind