Fazer query em um banco de dados e mostrar na tela com PHP
16/04/2019
0
Obs: esse código foi tão alterado que já nem sei se funciona em um servidor local.
$userget = $_GET[''usuario'']; $q2 = "select * from usuario where nome_user like :name"; $con = new PDO("mysql: host=$host; dbname=$db",$user,$senha); $result = $con->prepare($q2); $result->execute(array('':name'' => "%$userget%")); while($row = $result->fetch(PDO :: FETCH_ASSOC, PDO::FETCH_ORI_NEXT)){ print_r($row); echo "{ ''Nome usuario'' : ''".$row[''Nome_user'']."'' , ''email'' : ''".$row[''Email'']."'', ''Senha'' : ''".$row[''Senha'']."'' }<br>"; } /* foreach ($result->fetch(PDO::FETCH_ASSOC) as $row) { echo "{ ''Nome usuario'' : ''".$row[''Nome_user'']."'' , ''email'' : ''".$row[''Email'']."'', ''Senha'' : ''".$row[''Senha'']."'' }<br>";}*/
Alan
Post mais votado
20/04/2019
$userget = $_GET['usuario']; $q2 = "select * from usuario where nome_user like '%".$userget."%'"; $con = mysqli_connect($host,$user,$senha,$db); $result = $con->query($q2); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "{ 'Nome usuario' : '".$row["Nome_user"]."' , 'email' : '".$row["Email"]."', 'Senha' : '".$row["Senha"]."' }<br>"; }//fim while } // fim if result else { echo "0 results"; }// fim else result mysqli_close($con);
Alan
Mais Posts
17/04/2019
Alex William
Você atribuiu os valores corretos para as variaveis $host, $db, $user e $senha ???
O PDO está habilitado no servidor online? Qual a versão do PHP do servidor?
Poderia tirar um print e enviar o php_info() do seu servidor para que possamos ver a configuração do seu servidor?
20/04/2019
Alan
PHP Version 7.1.26
System: Linux 76385.us-imm-node6b.000webhost.io 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 i686
Build Date: Jan 9 2019 08:03:32
Server API: Apache 2.0 Handler
Virtual Directory Support: disabled
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan this dir for additional .ini files: /etc/php.d
Additional .ini files parsed: /etc/php.d/20-bcmath.ini, /etc/php.d/20-bz2.ini, /etc/php.d/20-calendar.ini, /etc/php.d/20-ctype.ini, /etc/php.d/20-curl.ini, /etc/php.d/20-dom.ini, /etc/php.d/20-exif.ini, /etc/php.d/20-fileinfo.ini, /etc/php.d/20-ftp.ini, /etc/php.d/20-gd.ini, /etc/php.d/20-gettext.ini, /etc/php.d/20-iconv.ini, /etc/php.d/20-intl.ini, /etc/php.d/20-json.ini, /etc/php.d/20-mbstring.ini, /etc/php.d/20-mcrypt.ini, /etc/php.d/20-mysqlnd.ini, /etc/php.d/20-pdo.ini, /etc/php.d/20-phar.ini, /etc/php.d/20-simplexml.ini, /etc/php.d/20-soap.ini, /etc/php.d/20-sockets.ini, /etc/php.d/20-sqlite3.ini, /etc/php.d/20-tokenizer.ini, /etc/php.d/20-xml.ini, /etc/php.d/20-xmlwriter.ini, /etc/php.d/20-xsl.ini, /etc/php.d/30-mysqli.ini, /etc/php.d/30-pdo_mysql.ini, /etc/php.d/30-pdo_sqlite.ini, /etc/php.d/30-wddx.ini, /etc/php.d/30-xmlreader.ini, /etc/php.d/30-xmlrpc.ini, /etc/php.d/40-zip.ini, /etc/php.d/zzz_custom.ini
PHP API: 20160303
PHP Extension: 20160303
Zend Extension: 320160303
Zend Extension Build: API320160303,NTS
PHP Extension Build: API20160303,NTS
Debug Build: no
Thread Safety: disabled
Zend Signal Handling: enabled
Zend Memory Manager: enabled
Zend Multibyte Support: provided by mbstring
IPv6 Support: enabled
DTrace Support: available, disabled
Registered PHP Streams: https, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip
Registered Stream Socket Transports: tcp, udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters: zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, bzip2.*, convert.iconv.*, mcrypt.*, mdecrypt.*
20/04/2019
Alan
$userget = $_GET['usuario']; $q2 = "select * from Usuario where Nome_user like :name"; $con = new PDO("mysql: host=$host; dbname=$db",$user,$senha); $result = $con->prepare($q2); $result->execute(array(':name' => "%$userget%")); while($row = $result->fetch(PDO :: FETCH_BOTH, PDO::FETCH_ORI_NEXT)){ echo "{ 'Nome usuario' : ' ".$row['Nome_user']." ' , 'email' : ' ".$row['Email']." ', 'Senha' : ' ".$row['Senha']." ' }<br>"; }
Só ainda não entendi porque de outras formas não estava funcionando :/
Clique aqui para fazer login e interagir na Comunidade :)