Mysqli – Conexiunea la baza de date

postat acum 4 ani de Stefanescu Mihai in categorie PHP

Pentru a ne conecta la baza de date MySqli (MySql improved) ne pune la dispozitie doua metode, una procedurala si una oprientata pe obiecte.

Procedural

Avem urmatoarea sintaxa:

$link = mysqli_connect("host","user","parola","baza_de_date") or die("Eroare: " . mysqli_error($link));

 Orientat pe obiecte

Avem urmatoarea sintaxa:

$mysqli = new mysqli("host", "user", "parola", "baza_de_date");
if ($mysqli->connect_errno) {
    echo "Nu ma pot conecta: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

Avem urmatorii parametri:

Parametru Descriere
host Host-ul pe care ruleaza baza de date.In mod default este localhost si portul este 3306
user User-ul care are acces la baza de date.
parola Parola userului care are acces la baza de date.
baza_de_date Baza de date la care dorim sa ne conectam.

Inchiderea conexiunii

Avem o functie ce ne ajuta sa inchidem conexiunea la baza de date. Aceasta functie are nevoie de un parametru resource (conexiunea la baza de date). Returneaza true in cazul in care a inchis conexiunea altfel returneaza false.

mysqli_close($mysqli);

sau in stilul orientat pe obiecte

$mysqli->close();

 

Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Acest articol a fost mutat de pe vechea platforma.
Pentru orice eroare aparuta la mutare va rog sa ma contactati!

Comentariu postate de minecraft download free la data de 14.05.2019
I'm now not sure the place you are getting your info, but great topic. I must spend some time studying more or figuring out more. Thank you for excellent information I was searching for this info for my mission.
Comentariu postate de kd 10 la data de 15.05.2019
I simply wanted to compose a quick note to appreciate you for some of the amazing tips and hints you are showing at this site. My time intensive internet search has at the end of the day been paid with useful knowledge to go over with my companions. I would assert that we site visitors actually are undeniably fortunate to dwell in a really good place with many awesome professionals with very helpful strategies. I feel quite blessed to have seen your entire site and look forward to tons of more fun moments reading here. Thank you again for everything.
Comentariu postate de how to download minecraft la data de 15.05.2019
When someone writes an paragraph he/she keeps the idea of a user in his/her brain that how a user can know it. Therefore that's why this post is perfect. Thanks!
Comentariu postate de minecraft free download la data de 16.05.2019
Amazing! This blog looks just like my old one! It's on a completely different topic but it has pretty much the same layout and design. Wonderful choice of colors!
Comentariu postate de how to download minecraft la data de 16.05.2019
Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a bit, but other than that, this is wonderful blog. A great read. I will definitely be back.
Comentariu postate de free minecraft download la data de 17.05.2019
Can you tell us more about this? I'd love to find out more details.
Comentariu postate de how to download minecraft la data de 18.05.2019
Hi there, I want to subscribe for this weblog to get most up-to-date updates, so where can i do it please help.