Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Błąd połączenia z mysql
o2w5n778
post
Post #1





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

Ostrzeżenie: (0%)
-----


Witam!
Stworzyłem połączenie z mysql z 2 plików:
index.php
  1. <?php
  2.  
  3. require('process.php');
  4.  
  5. $mysql->connect('localhost','root','pass','cms');
  6.  
  7. echo('asd');
  8.  
  9. ?>


Process.php
  1. <?php
  2.  
  3. $mysql = new mysql;
  4. class mysql{
  5.  
  6. function connect($dbhost, $dbuser, $dbpass, $dbname){
  7. mysql_connect($dbhost, $dbuser, $dbpass) or die mysql_error();
  8. }
  9.  
  10. }
  11.  
  12. ?>


Zwraca mi błąd ponieważ nie wykonuje dalszej części skryptu echo. Nie wiem jaki to błąd ponieważ mój serwer nie wyświetla tego ale dane są wpisane na 100% poprawne
Go to the top of the page
+Quote Post
epeaxx
post
Post #2





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 8.06.2011

Ostrzeżenie: (0%)
-----


Zmień nazwę pliku Process.php na process.php bo taki dołączasz w pliku index.php
Go to the top of the page
+Quote Post
o2w5n778
post
Post #3





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

Ostrzeżenie: (0%)
-----


zmieniłem i nic nie dało
Go to the top of the page
+Quote Post
epeaxx
post
Post #4





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 8.06.2011

Ostrzeżenie: (0%)
-----


Wywal z pliku process.php:

Kod
$mysql = new mysql;


i wstaw w pliku index.php przed:

Kod
$mysql->connect('localhost','root','pass','cms');
Go to the top of the page
+Quote Post
o2w5n778
post
Post #5





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

Ostrzeżenie: (0%)
-----


zrobiłem jak mówisz. Zwraca mi:
  1. Fatal error: Call to undefined function mysql_connect() in C:\Program Files (x86)\Serwer\Apache\htdocs\plog\process.php on line 6

  1. <?php
  2.  
  3. class mysql{
  4.  
  5. function connect($dbhost, $dbuser, $dbpass, $dbname){
  6. mysql_connect($dbhost, $dbuser, $dbpass);
  7. mysql_select_db($dbname);
  8. }
  9.  
  10. }
  11.  
  12. ?>


Ten post edytował o2w5n778 16.09.2011, 12:15:01
Go to the top of the page
+Quote Post
gylopl
post
Post #6





Grupa: Zarejestrowani
Postów: 82
Pomógł: 1
Dołączył: 6.04.2008

Ostrzeżenie: (0%)
-----


a serwer dobrze skonfigurowales?
Go to the top of the page
+Quote Post
o2w5n778
post
Post #7





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

Ostrzeżenie: (0%)
-----


A trzeba coś konfigurować bo jak narazie to zainstalowałem to jako moduł do apache i wszystko ładnie śmigało jak do tej pory.

Ten post edytował o2w5n778 16.09.2011, 12:41:35
Go to the top of the page
+Quote Post
gylopl
post
Post #8





Grupa: Zarejestrowani
Postów: 82
Pomógł: 1
Dołączył: 6.04.2008

Ostrzeżenie: (0%)
-----


  1. <?php
  2.  
  3.  
  4. class mysql{
  5.  
  6. function connect($dbhost, $dbuser, $dbpass, $dbname){
  7. mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
  8. }
  9. }
  10. $mysql = new mysql;
  11. $mysql->connect('localhost','root','','cms');
  12.  
  13. $test = mysql_fetch_array(mysql_query("SELECT * FROM test WHERE id =1"));
  14. echo $test['wartosc'];
  15. ?>

u mnie to dziala.
Go to the top of the page
+Quote Post
nospor
post
Post #9





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




@gylopl przeczytałeś komunikat błędy? Koleś nie ma mysql.

Cytat
A trzeba coś konfigurować bo jak narazie to zainstalowałem to jako moduł do apache i wszystko ładnie śmigało jak do tej pory.
Tak, jeśli chcesz używać mysql to musisz doinstalować moduł mysql. Wszystko masz w necie opisane.
Go to the top of the page
+Quote Post
o2w5n778
post
Post #10





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

Ostrzeżenie: (0%)
-----


mam zainstalowane mysql server 5.5
Go to the top of the page
+Quote Post
nospor
post
Post #11





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Ale masz jeszcze zainstalować moduł mysql php
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 14:30