AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   sql-problem (https://forums.alliedmods.net/showthread.php?t=57392)

lagbeast 07-03-2007 19:26

sql-problem
 
Hi everyone. Here is my problem. I am using a code-snipplet (after many failed attempts to make my own) and my problem is that the script says that there is no table in my db, but the table is there. Please tell my that im retarded and that i just missed something like that u cant use this on an mysql-server?

The errormessage that I get is "No such table db|1"

Here is the code:
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <dbi>


public plugin_init()
{
    
//Create a connection
    
new Sql:mysql dbi_connect("localhost""root""""mysql")

//If the connection is less than 1, it is bad   
    
if (mysql SQL_OK) {
        new 
err[255]
        new 
errNum dbi_error(mysqlerr254)
        
server_print("error1: %s|%d"errerrNum)
        return 
1
    
}
    
    
server_print("Connection handle: %d"mysql)
    
//Do a select query 
    
new Result:res dbi_query(mysql"SELECT * FROM db")

//If the query is greater than 0, you got a handle to the result set    
    
if (res <= RESULT_NONE) {
        new 
err[255]
        new 
errNum dbi_error(mysqlerr254)
        
server_print("error3: %s|%d"errerrNum)
        return 
1
    
}
    
    
server_print("Result handle: %d"res)

//Loop through the result set   
    
while (res && dbi_nextrow(res)>0) {
        new 
qry[32]
//Get the column/field called "keyname" from the result set
        
dbi_result(res"id"qry32)
        
server_print("result: %s"qry)
    }

//Free the result set   
    
dbi_free_result(res)


and my database looks like this

Code:

-- phpMyAdmin SQL Dump
-- version 2.6.1
-- http://www.phpmyadmin.net
--
-- Värd: localhost
-- Skapad: 03 juli 2007 kl 04:22
-- Serverversion: 4.1.9
-- PHP-version: 4.3.10
--
-- Databas: `mysql`
--
CREATE DATABASE `mysql` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE mysql;

-- --------------------------------------------------------


--
-- Struktur för tabell `db`
--

CREATE TABLE `db` (
  `Host` char(60) character set latin1 collate latin1_bin NOT NULL default '',
  `Db` char(64) character set latin1 collate latin1_bin NOT NULL default '',
  `User` char(16) character set latin1 collate latin1_bin NOT NULL default '',
  `Select_priv` enum('N','Y') NOT NULL default 'N',
  `Insert_priv` enum('N','Y') NOT NULL default 'N',
  `Update_priv` enum('N','Y') NOT NULL default 'N',
  `Delete_priv` enum('N','Y') NOT NULL default 'N',
  `Create_priv` enum('N','Y') NOT NULL default 'N',
  `Drop_priv` enum('N','Y') NOT NULL default 'N',
  `Grant_priv` enum('N','Y') NOT NULL default 'N',
  `References_priv` enum('N','Y') NOT NULL default 'N',
  `Index_priv` enum('N','Y') NOT NULL default 'N',
  `Alter_priv` enum('N','Y') NOT NULL default 'N',
  `Create_tmp_table_priv` enum('N','Y') NOT NULL default 'N',
  `Lock_tables_priv` enum('N','Y') NOT NULL default 'N',
  PRIMARY KEY  (`Host`,`Db`,`User`),
  KEY `User` (`User`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Database privileges';

-- --------------------------------------------------------


lagbeast 07-04-2007 08:37

Re: sql-problem
 
Does anyone have any ideas?

raa 07-04-2007 14:39

Re: sql-problem
 
This is how one of my plugins connects
Code:
#define MAX_NAME_LENGTH 31 new g_host[MAX_NAME_LENGTH+1], g_user[MAX_NAME_LENGTH+1], g_pass[MAX_NAME_LENGTH+1], g_dbname[MAX_NAME_LENGTH+1], g_error[MAX_NAME_LENGTH+1] public function() { g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH) }

lagbeast 07-04-2007 16:33

Re: sql-problem
 
Do you think its the connection thats the problem or is it the part of selecting a table? Does anyone have a fail-safe way to connect and read a line from a sql-table. Easy and simple? If you do please paste it here. Thx a lot!

mysticssjgoku4 07-04-2007 19:35

Re: sql-problem
 
ius the table "db" in the DATABASE "mysql" ?

lagbeast 07-04-2007 20:07

Re: sql-problem
 
yes

lagbeast 07-04-2007 20:33

Re: sql-problem
 
Alright. I used hawks code instead and it works now. Now ive been looking here http://www.amxmodx.org/funcwiki.php?go=func&id=1105 at the SQLReadResult, and i get it working, now i just dont know how to get out the info.

PHP Code:

 // run a random query
    
new Handle:Query SQL_PrepareQuery(SqlConnection,"SELECT * FROM login")
 
    
// run the query
    
if(!SQL_Execute(Query))
    {
        
// if there were any problems
        
SQL_QueryError(Query,g_Error,511)
        
set_fail_state(g_Error)
    }
 
    
// checks to make sure there's more results
    // notice that it starts at the first row, rather than null
    
new Data
    
while(SQL_MoreResults(Query))
    {
        
// columns start at 0
        
Data SQL_ReadResult(Query,1)
 
        
server_print("Found data: %d",Data)
        
SQL_NextRow(Query)
    } 

Example: I have a table named login and i want to get out the info in the second column called nick and i want to store that info in a string. How the hell do i do that?

lagbeast 07-05-2007 09:53

Re: sql-problem
 
Noone has an idea?

YamiKaitou 07-05-2007 10:05

Re: sql-problem
 
PHP Code:

new nick[64];
SQL_ReadResult(Query,SQL_FieldToNum(Query,"nick"),nick,63); 


lagbeast 07-05-2007 13:16

Re: sql-problem
 
Quote:

Originally Posted by YamiKaitou (Post 499007)
PHP Code:

new nick[64];
SQL_ReadResult(Query,SQL_FieldToNum(Query,"nick"),nick,63); 


IT doesnt work. I just keep getting int-values from the db, when the values in the db are STR. What im looking for is this.

PHP Code:

$array mysql_query("SELECT * FROM login");
while(
$row mysql_fetch_array($array)) 
{
  echo  
$row[nick];


This is how it would have looked in php.


All times are GMT -4. The time now is 21:26.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.